// JavaScript Document
$(function(){
	changeImg();
	window.onscroll = goTop; 
});

var index=0;
function antoChangeImg(){
	index++;
	index=Math.abs(index);
	index=index%3;
	var lis=$(".scenery").find("li");
	for(var i=0;i<lis.length+0;i++) {
		if(index==i) {
			$(lis[i]).css("display","block");
		}else{
			$(lis[i]).css("display","none");
		}
	}
}

//图片自动变换
function changeImg(){
	var mt=window.setInterval("antoChangeImg()",2000);
	$(".scenery").mouseenter(function(){
		window.clearInterval(mt);
	});
	$(".scenery").mouseleave(function(){
		mt=window.setInterval("antoChangeImg()",2000);
	});
}

//图片左右变换
function goTo(val){
	if(val=="left"){
		index--;
	}else{
		index++;
	}
	var n=Math.abs(index%3);
	var lis=$(".scenery").find("li");
	for(var i=0;i<lis.length+0;i++) {
		if(n==i) {
			$(lis[i]).css("display","block");
		}else{
			$(lis[i]).css("display","none");
		}
	}
}

//页面跳转
function lookDetail(val){
		$.ajax({
		    url: "../json/LocalInfo_getInfoByLid",    //请求的url地址
		    dataType: "json",   //返回格式为json
		    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
		    type: "POST",
		    data:{"lid":val},
		    success: function(data) {
		    	if(data.obj==1){
		    		location.href="scenery_detail.jsp?id="+val;
		    	}else{
		    		$.messager.alert('错误提示','网络错误...','error');	
		    	}
		    }
		});
}

//返回顶部
function goTop(){
    var t = document.documentElement.scrollTop || document.body.scrollTop; 
    var top_div = $("#to_top");
    if( t >= 200 ) {
        $(top_div).css("display","block");
    } else {
        $(top_div).css("display","none");
    }
	
	$(top_div).click(function(){
		$(document).scrollTop(0);
	});	
} 


//搜索
function searchInfo(){
	var info=$("#search_info").val();
	$(function(){
		var url=location.href;
		var searchInfo=url.substring(url.indexOf("=") + 1, url.length);
		console.info(url);
		$.ajax({
		    url: "../json/LocalInfo_getSearchInfo",    //请求的url地址
		    dataType: "json",   //返回格式为json
		    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
		    type: "POST",
		    data:{"lname":info},
		    success: function(data) {
		    	if(data.obj==1){
		    		location.href="scenery_result.jsp?info="+info;
		    	}else{
		    		$.messager.alert('错误提示','网络错误...','error');	
		    	}
		    }
		});
	});
}

//前往论坛
function goBBS(val){
	$.post("../json/Forum_goForum",{"forum.lid":val},function(data){
		if(data.obj != null){
			location.href="city_bbs.jsp";
		}
	},"json");
}


